/**
 * 
 */
package cc.monggo.util.filesystem;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author fangjinsong
 *
 */
public class FileUtils {	
	public static String getFileAsString(String path){
		File file = new File(path);
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			
			StringBuffer s = new StringBuffer();
			String temp = br.readLine();
			while(temp != null){
				s.append(temp);
				temp = br.readLine();
			}
			s.append(temp);
			return s.toString();			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		return "";
	}
	
	public static void outputAsFile(String path,String source){
		File file = new File(path);
		FileOutputStream fs ;
		try {
			fs = new FileOutputStream(file);
			byte[] s = source.getBytes();
			fs.write(s,0,s.length);
			fs.flush();
			fs.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
	}
}
